package logic

import (
	"context"
	"fmt"

	"server_1.0/service/personality/internal/svc"
	"server_1.0/service/personality/personality"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQueryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryLogic {
	return &QueryLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QueryLogic) Query(in *personality.Empty) (*personality.QReps, error) {
	usersHandle := make([]*personality.Reps, 0)
	count := 0
	pnos, _ := l.svcCtx.PersonModel.GetAll(l.ctx)
	fmt.Println(pnos)
	for _, item := range pnos {
		usersHandle = append(
			usersHandle,
			&personality.Reps{
				No:   item.Pno,
				Name: item.Pname,
			})
		count += 1
	}
	return &personality.QReps{
		Count: int64(count),
		QRs:   usersHandle,
	}, nil
}
